<style>
</style>

<template>
  <div class="manage-wrap">
    <Card style="width:550px">
      <p slot="title">
        <Icon type="ios-build" />推送设置
      </p>
      <Row style="margin-left:210px;line-height:50px;">
        <Col span="8">
          短信
          <Icon :size="16" type="logo-twitch" />
        </Col>
        <Col span="8">
          语音
          <Icon :size="16" type="md-volume-up" />
        </Col>
        <Col span="8">
          微信
          <CommonIcon :size="16" type="_wechat" />
        </Col>
      </Row>
      <Form :label-width="150" value="true" style="padding: 3px 60px" v-if="hasGetPushConfig">
        <!-- <Form-item label="推送模板">
          <Select v-model="configId" placeholder="请选择" filterable>
            <Option
              v-for="item in configCombo"
              :value="item.value"
              :key="item.value"
            >{{ item.label }}</Option>
          </Select>
        </Form-item> -->
        <Form-item label="消防安全月报推送邮箱">
          <Input v-model="email"></Input>
        </Form-item>
        <Form-item label="火警推送">
          <Row>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.fire[0]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.fire[1]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.fire[2]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
          </Row>
        </Form-item>
        <Form-item label="故障推送">
          <Row>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.breakdown[0]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.breakdown[1]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.breakdown[2]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
          </Row>
        </Form-item>
        <Form-item label="离线推送">
          <Row>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.offline[0]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.offline[1]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.offline[2]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
          </Row>
        </Form-item>
        <Form-item label="拆卸推送">
          <Row>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.unload[0]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.unload[1]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.unload[2]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
          </Row>
        </Form-item>
        <Form-item label="清除告警推送">
          <Row>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.clear[0]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.clear[1]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
            <Col span="8">
              <i-switch size="large" v-model="ConfigInfo.clear[2]">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
            </Col>
          </Row>
        </Form-item>
        <!-- <Form-item label="备注">
          <Input
            v-model="ConfigInfoFrom.remark"
            type="textarea"
            :rows="4"
          />

        </Form-item>-->
        <FormItem>
          <Button type="primary" :loading="loading" @click="saveForm">提交</Button>
        </FormItem>
      </Form>
    </Card>
  </div>
</template>

<script>
import { pushConfigInfo, updateConfigInfo, configCombo } from "@/api/system";
import CommonIcon from "_c/common-icon";
export default {
  components: {
    CommonIcon
  },
  data() {
    return {
      ConfigInfoFrom: {
        fire: "",
        breakdown: "",
        offline: "",
        unload: "",
        clear: ""
        // remark: ""
      },
      ConfigInfo: {
        fire: [false, false, false],
        breakdown: [false, false, false],
        offline: [false, false, false],
        unload: [false, false, false],
        clear: [false, false, false]
      },
      loading: false,
      hasGetPushConfig: false,
      configCombo: [],
      configId: "",
      email: null
    };
  },
  computed: {},
  created() {},
  mounted() {
    this.$nextTick(() => {
      // this.getConfigCombo();
      this.pushConfigInfo();
    });
  },
  methods: {
    async pushConfigInfo() {
      const result = await pushConfigInfo();
      if (result.code == 0) {
        if (result.data) {
          this.ConfigInfoFrom = result.data;
          // this.configId = result.data.configId;
          this.email = result.data.email;
          for (var key in this.ConfigInfo) {
            if (this.ConfigInfoFrom[key]&&this.ConfigInfoFrom[key].indexOf("a") > -1) {
              this.ConfigInfo[key][0] = true;
            } else {
              this.ConfigInfo[key][0] = false;
            }
            if (this.ConfigInfoFrom[key]&&this.ConfigInfoFrom[key].indexOf("b") > -1) {
              this.ConfigInfo[key][1] = true;
            } else {
              this.ConfigInfo[key][1] = false;
            }
            if (this.ConfigInfoFrom[key]&&this.ConfigInfoFrom[key].indexOf("c") > -1) {
              this.ConfigInfo[key][2] = true;
            } else {
              this.ConfigInfo[key][2] = false;
            }
          }
        }
        this.hasGetPushConfig = true;
      }
    },
    async getConfigCombo() {
      let res = await configCombo();
      if (res.code == 0) {
        console.log(res);
        this.configCombo = res.data;
      }
    },
    async saveForm() {
      this.loading = true;
      for (var key in this.ConfigInfo) {
        let configValue = [];
        if (this.ConfigInfo[key][0]) {
          configValue.push("a");
        }
        if (this.ConfigInfo[key][1]) {
          configValue.push("b");
        }
        if (this.ConfigInfo[key][2]) {
          configValue.push("c");
        }
        this.ConfigInfoFrom[key] = configValue.join(",");
      }
      let params = JSON.parse(JSON.stringify(this.ConfigInfoFrom));
      // params.configId = this.configId;
      params.email = this.email;
      try {
        let result = await updateConfigInfo(params);

        if (result.code == "0") {
          this.$Message.success("提交成功!");
        } else {
          this.$Message.error(result.msg);
        }
      } catch (e) {
        this.$Message.error("服务器异常，稍后再试");
      }
      this.loading = false;
    }
  }
};
</script>
